package com.hyx.bookManager.controller;

import com.hyx.bookManager.domain.common.CommonResult;
import com.hyx.bookManager.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @ClassName UserController
 * @Description TODO
 * @Author 黄乙轩
 * @Date 2021/6/7 21:25
 * @Version 1.0
 **/

@CrossOrigin
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;


    @ResponseBody
    @RequestMapping("/login")
    public CommonResult login(@RequestBody Map<String,String> map){
        String ammount = map.get("ammount");
        String password = map.get("password");
        return userService.loginUser(ammount,password);
    }

    @ResponseBody
    @RequestMapping("/getCode")
    public CommonResult getCode(@RequestBody Map<String,String> map){
        String email = map.get("email");
        return userService.getCode(email);
    }

    @ResponseBody
    @RequestMapping("/register")
    public CommonResult register(@RequestBody Map<String,String> map){
        String name = map.get("name");
        String email = map.get("email");
        String password = map.get("password");
        String code = map.get("code");
        return userService.registerUser(Integer.valueOf(code),name,password,email);
    }

}
